package edu.uta.cfl.GUI;

import java.util.ArrayList;

import edu.uta.cfl.data.Combo;
import edu.uta.cfl.data.IterationResult;
import edu.uta.cfl.data.Parameter;
import edu.uta.cfl.data.SUT;

/**
 * To load suspicious combinations from the IterationResult.java class
 * @author jagan
 *
 */
public class LoadSuspiciousCombination {


	private IterationResult iteration;
	private SUT sut;
	private ArrayList<String> suspiciousCombination = new ArrayList<String>();
	private Integer parameterCount = 0;
	private Integer curCumLen =0;

	/**
	 * @return the parameterCount
	 */
	public Integer getParameterCount() {
		return parameterCount;
	}

	public LoadSuspiciousCombination(IterationResult itr, SUT sut,Integer curCmbLen) {
		super();
		this.iteration = itr;
		this.sut = sut;
		this.curCumLen = curCmbLen;
	}

	public void loadColumnInformation(IterationResult itr)
	{
		String[] columnData = new String[] { "Rank",
				"Sus of Combo", "Sus of Environment" };

	}

	public ArrayList<String> getSuspiciousCombinations()
	{
		int rowIndex = 1;
		for (Combo cmb : sut.getSuspiciousCombos(curCumLen)) {
			
			String susCombination = rowIndex+","+cmb.getRank() + ","
					+ printPN_PV(cmb, sut.getParameters())
					+ String.format("%f", cmb.getRankValue()) + ","
					+ String.format("%f", cmb.getEnvRankValue());

			suspiciousCombination.add(susCombination);
			rowIndex++;
		}

		return suspiciousCombination;
	}

	private String printPN_PV(Combo cmb, ArrayList<Parameter> parameters) {


		//String output = "";
		String formattedOutput = "";
		int count = 0;
		for (edu.uta.cfl.data.Component cmp1 : cmb.getComponent()) {
			Parameter prm = parameters.get(parameters.indexOf(cmp1
					.getParameter()));
			//output += "Parameter 1: " + prm.getName() + "\nParameter Value:  "
					//+ prm.getValues().get(cmp1.getValue()) + "\n";
			formattedOutput += prm.getName() + ","
					+ prm.getValues().get(cmp1.getValue()) + ",";
			count++;
		}
		parameterCount = count;
		System.out.println("Testing parameter Count:"+parameterCount);
		return formattedOutput;

	}

}
